Google Cloud AI Services Quick Start Guide by Arvind Ravulavaru

Google Cloud AI Services Quick Start Guide by Arvind Ravulavaru

Author:Arvind Ravulavaru
Language: eng
Format: epub
Tags: COM004000 - COMPUTERS / Intelligence (AI) and Semantics, COM018000 - COMPUTERS / Data Processing, COM044000 - COMPUTERS / Neural Networks
Publisher: Packt Publishing
Published: 2018-05-30T06:10:19+00:00


Creating the Vision API service

To upload the image to our server, we are using postFile() on VisionAPIService. Let's create this service now. Inside the client\app\services folder, create a file named vision.api.service.ts and update it as follows:

// SNIPP SNIPP

import { Injectable } from '@angular/core';

import { HttpClient } from '@angular/common/http';

import { Observable } from 'rxjs/Observable';

@Injectable()

export class VisionAPIService {

constructor(private http: HttpClient) {}

postFile(threadId: string, fileToUpload: File): Observable < any > {

const formData: FormData = new FormData();

formData.append('image-reply', fileToUpload, fileToUpload.name);

return this.http.post < any > (`/api/upload-image/${threadId}`, formData);

}

}

// SNIPP SNIPP

We need to add this service as a provider in client\app\app.module.ts. First, we will import VisionAPIService into client\app\app.module.ts:

// SNIPP SNIPP

import { VisionAPIService } from './services/vision.api.service';

// SNIPP SNIPP

Update the providers as follows:

// SNIPP SNIPP

providers: [

AuthService,

AuthGuardLogin,

AuthGuardAdmin,

UserService,

ThreadService,

MessageService,

VisionAPIService,

{

provide: HTTP_INTERCEPTORS,

useClass: TokenInterceptor,

multi: true

}

],

// SNIPP SNIPP

Save all the files to continue.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.